﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI;
using FlexCell;
using YArchitech.Controls;

namespace YJKArch.StatisticTable
{
	internal class InteriorDecorationGrid1
	{
		public InteriorDecorationGrid1(ExternalCommandData commandData, ref FlexCell.Grid grid, string gridFilePath, string gridName, int nFilterArea)
		{
			this.m_grid = grid;
			this.m_doc = commandData.Application.ActiveUIDocument.Document;
			this.m_strGridName = gridName;
		}

		public bool GetStatisticGrid()
		{
			this.StatisticData();
			this.m_grid.Locked = false;
			return this.SetDataToGrid();
		}

		private void StatisticData()
		{
			if (this.m_doc == null)
			{
				return;
			}
			try
			{
				foreach (Element element in new FilteredElementCollector(this.m_doc).OfClass(typeof(Room)).ToElements())
				{
				}
			}
			catch
			{
				YJKMessageBox.Show("快速统计出错");
			}
		}

		private bool SetDataToGrid()
		{
			if (this.m_dicData.Count <= 0 || this.m_grid == null)
			{
				YJKMessageBox.Show("没有统计数据");
				return false;
			}
			int num = 2;
			this.m_grid.Range(num + 1, 1, this.m_grid.Rows - 1, this.m_grid.Cols - 1).DeleteByRow();
			int num2 = 0;
			foreach (KeyValuePair<string, List<string>> keyValuePair in this.m_dicData)
			{
				List<string> value = keyValuePair.Value;
				num2 += value.Count;
			}
			this.m_grid.Rows = num + num2 + 1;
			foreach (KeyValuePair<string, List<string>> keyValuePair2 in this.m_dicData)
			{
				List<string> value2 = keyValuePair2.Value;
				num++;
				for (int i = 1; i < value2.Count; i++)
				{
					this.m_grid.Cell(num, i).Text = value2[i];
					this.m_grid.Cell(num, i).Alignment = AlignmentEnum.CenterCenter;
					this.m_grid.Cell(num, i).set_Border(EdgeEnum.Outside, LineStyleEnum.Thin);
				}
			}
			return true;
		}

		private FlexCell.Grid m_grid;

		private Autodesk.Revit.DB.Document m_doc;

		private string m_strGridName = "";

		private Dictionary<string, List<string>> m_dicData = new Dictionary<string, List<string>>();
	}
}
